<?php 
$w = $table['ModelTable']['width'];
$h = $table['ModelTable']['height'];

$cellw = 15;
$cellh = 15;
function tr_style($tr,$w = 15,$h = 15){
	if($tr['direct']){
		return "height:{$h}px;width:".$w*$tr['z']."px;top:".$h*$tr['y']."px;left:".$w*$tr['x'].'px';
	}else{
		return "width:{$h}px;height:".$w*$tr['z']."px;top:".$h*$tr['y']."px;left:".$w*$tr['x'].'px';
	}
}
function getTd($tr,$y){
	$res = array('id'=>'','name'=>'','enable'=>0);
	foreach ($tr['ModelTd'] as $td){
		if($td['y'] == $y){
			$res = $td;
			break;
		}
	}
	return $res;
}
?>
<div id = 'seat_map'>
<table class = 'crood'>
<?php for ($i=0;$i<=$h;$i++){?>
<tr>
	<?php for ($j=0;$j<=$w;$j++){?>
		<?php if($i==0):?>
		    <th><?php echo $j?></th>
		<?php elseif($j == 0):?>
			<th><?php echo $i?></th>
		<?php else:?>
			<td></td>
		<?php endif;?>
    <?php }?>
</tr>
<?php }?>
</table>
<div class = 'seat' style = 'width:<?php echo ($w+1)*$cellw?>px;height:<?php echo ($h+1)*$cellh?>px;'>
<?php foreach ($table['ModelTr'] as $tr):?>
<ul class = 'seat_tr seat_tr_<?php echo $tr['id']?>' 
	title = '<?php echo $tr['name']?>'
	style = "<?php echo tr_style($tr)?>"
	data-id = "<?php echo $tr['id']?>"
	data-value = '<?php //echo json_encode($tr)?>'
>
	<?php for ($i=0;$i<$tr['z'];$i++){?>
		<?php 
		if(isset($tr['ModelTd'])):
			$td = getTd($tr,$i)
		?>
		<li class = 'seat_td <?php echo 'seat_is_'.$td['enable']?>' 
			style = 'width:<?php echo $cellw ?>px;height:<?php echo $cellh?>px'
			data-tr = "<?php echo $tr['id']?>"
			data-td = "<?php echo $td['id']?>"
			data-index = "<?php echo $i?>"
			title = '<?php echo $td['name']!=''?$tr['name'].' '.$td['name'].'座':$tr['name']?>'
		><?php echo $td['name']?></li>
		<?php endif;?>
	<?php }?>
</ul>
<?php endforeach;?>
</div>
</div>
